﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;

namespace CubicFWNet.Data.SystemManager
{
    public class OperateRecordRepository : RepositoryBase<OperateRecord>
    {
        public int UpdateOperateRecord(OperateRecord web)
        {
            using (var db = new YJXErpContext())
            {
                var obj = db.OperateRecords.FirstOrDefault(a => a.ItemId == web.ItemId && a.TypeId == web.TypeId);
                if (obj != null)
                {
                    obj.EndTime = web.EndTime;
                    obj.CreatorId = web.CreatorId;
                    obj.CreatorName = web.CreatorName;
                    if (!string.IsNullOrEmpty(web.Describe))
                    {
                        obj.Describe = web.Describe;
                    }
                    if (!string.IsNullOrEmpty(web.Memo))
                    {
                        obj.Memo = web.Memo;
                    }
                }
                return db.SaveChanges();
            }
        }

        public int UpdateOrderStateById(Guid id, int status)
        {
            var obj = dbcontext.Orders.FirstOrDefault(a => a.Id == id);
            if (obj != null)
            {
                obj.Status = status;
            }
            return dbcontext.SaveChanges();
        }

        public int UpdateOrderStateAndIniById(Guid id, int status, decimal initPrice)
        {
            var obj = dbcontext.Orders.FirstOrDefault(a => a.Id == id);
            if (obj != null)
            {
                obj.Status = status;
                obj.InitPrice = initPrice;
            }
            return dbcontext.SaveChanges();
        }

    }
}
